# -*- coding: utf-8 -*-
#
#    pyqtsozluk, qtsozluk and pysozluk mix dictionary application
#    Copyright (C) 2007  pyqtsozluk authors
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

from PyQt4 import QtCore, QtGui
from gettext import translation
from pysozlukglobals import version
_ = translation('pyqtsozluk', fallback=True).ugettext

class SettingsBase(QtGui.QWidget):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)

        self.setWindowModality(QtCore.Qt.ApplicationModal)
        self.setWindowIcon(QtGui.QIcon("/usr/share/pyqtsozluk/images/configure.png"))
        self.settings = QtCore.QSettings()

        self.gridlayout = QtGui.QGridLayout(self)
        self.gridlayout.setMargin(9)
        self.gridlayout.setSpacing(6)

        self.shortcutGroupBox = QtGui.QGroupBox(self)
        self.shortcutGroupBox.setTitle(_("Shortcut Options"))

        self.gridlayout1 = QtGui.QGridLayout(self.shortcutGroupBox)
        self.gridlayout1.setMargin(9)
        self.gridlayout1.setSpacing(6)

        self.label = QtGui.QLabel(self.shortcutGroupBox)
        self.label.setText(_("Shortcut key for global search:"))
        self.gridlayout1.addWidget(self.label,0,0,1,1)

        self.globalShortcut = QtGui.QLineEdit(self.shortcutGroupBox)
        self.globalShortcut.setText(self.settings.value("shortcuts/global", QtCore.QVariant("ctrl+shift+t")).toString())
        self.gridlayout1.addWidget(self.globalShortcut,0,1,1,1)
        self.gridlayout.addWidget(self.shortcutGroupBox,0,0,1,1)

        self.checkUpdates = QtGui.QCheckBox(self)
        self.checkUpdates.setChecked(self.settings.value("checkUpdates", QtCore.QVariant(False)).toBool())
        self.checkUpdates.setText(_("Check for updates at startup"))
        self.gridlayout.addWidget(self.checkUpdates,1,0,1,1)

        self.smartSearch = QtGui.QCheckBox(self)
        self.smartSearch.setChecked(self.settings.value("search/smartSearch", QtCore.QVariant(True)).toBool())
        self.smartSearch.setText(_("Search online if offline search can't find any results"))
        self.gridlayout.addWidget(self.smartSearch,2,0,1,1)

        spacerItem = QtGui.QSpacerItem(20,40,QtGui.QSizePolicy.Minimum,QtGui.QSizePolicy.Expanding)
        self.gridlayout.addItem(spacerItem,3,0,1,1)

        self.buttonBox = QtGui.QDialogButtonBox(self)
        self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
        self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.NoButton|QtGui.QDialogButtonBox.Ok)

        self.gridlayout.addWidget(self.buttonBox,4,0,1,1)

        QtCore.QObject.connect(self.buttonBox,QtCore.SIGNAL("accepted()"),self.accept)
        QtCore.QObject.connect(self.buttonBox,QtCore.SIGNAL("rejected()"),self.reject)

        if self.settings.contains("configwindowposition"):
            self.move(self.settings.value("configwindowposition").toPoint())
        else:
            self.dw = QtGui.QDesktopWidget()
            self.move((self.dw.screenGeometry(self.dw.primaryScreen())).width()-self.width(), (self.dw.screenGeometry(self.dw.primaryScreen()).height())/2 )
        self.show()

    def accept(self):
        self.settings.setValue("configwindowposition", QtCore.QVariant(self.pos()))
        self.settings.setValue("shortcuts/global", QtCore.QVariant(self.globalShortcut.text()))
        self.settings.setValue("checkUpdates", QtCore.QVariant(self.checkUpdates.isChecked()))
        self.settings.setValue("search/smartSearch", QtCore.QVariant(self.smartSearch.isChecked()))
        self.hide()

    def reject(self):
        self.hide()

class AboutBase:
    def __init__(self, parent=None):
        QtGui.QMessageBox.about(parent,
                                _("About PyQtSozluk"),
                                "PyQtSozluk v%s\n" % version +\
                                "http://code.google.com/p/pyqtsozluk\n\n" +\
                                _("Developers:") + "\n" +\
                                u"İlker Kesen <ilker.kde at gmail.com>" + "\n" +\
                                u"İşbaran Akçayır <isbaran at gmail.com>" + "\n" +\
                                u"Uğur Çetin <ugur.jnmbk at gmail.com>")
